package com.bestcem.xm.txtanls.enums;

import lombok.Getter;

/**
 * @author liheng
 * @version v1.0
 * @date 2021/5/14 17:16
 */
@Getter
public enum EmotionKeyEnum {
    /**
     * 原话情感正向
     */
    POS(0, "pos", 1, "正向"),

    /**
     * 原话情感负向
     */
    NEG(1, "neg", -1, "负向"),

    /**
     * 原话情感中性
     */
    NEU(2, "neu", 0, "中性"),

    /**
     * 原话情感混合
     */
    MIX(3, "mix", 3, "混合"),

    /**
     * 原话情感好评
     */
    GOOD(4, "good", 1, "好评"),

    /**
     * 原话情感差评
     */
    BAD(5, "bad", -1, "差评"),

    /**
     * 所有提及情感
     */
    MENTION(6, "mention", null, "所有提及");

    private final int index;
    private final String key;
    private final String name;
    private final Integer viewpointScore;


    EmotionKeyEnum(int index, String key, Integer viewpointScore, String name) {
        this.index = index;
        this.key = key;
        this.name = name;
        this.viewpointScore = viewpointScore;
    }
    public static Integer getIndexByKey(String key) {
        for (EmotionKeyEnum value : values()) {
            if (value.getKey().equals(key)) {
                return value.getIndex();
            }
        }
        return null;
    }

    public static String getKeyByIndex(int index) {
        for (EmotionKeyEnum value : values()) {
            if (value.getIndex() == index) {
                return value.getName();
            }
        }
        return "";
    }


    /**
     * 获取原话对应观点情感得分
     *
     * @param index
     * @return
     */
    public static Integer getViewpointScore(int index) {
        for (EmotionKeyEnum value : values()) {
            if (value.getIndex() == index) {
                // 好评差评特殊处理

                return value.getViewpointScore();
            }
        }
        return null;
    }
}
